<template>
  <div class="header">
    <router-link tag="div" to="/" class="header-abs">
      <!-- 暂时解决方案  keepalive 设置 eclude引起的bug -->
      <div @click="handleRemoveScroll" class="iconfont header-abs-back">&#xe624;</div>
    </router-link>
    <div
      class="header-fixed"
      v-show="showAbs"
      :style="opacityStyle"
    >
      <router-link to="/">
        <!-- 暂时解决方案  keepalive 设置 eclude引起的bug -->
        <div @click="handleRemoveScroll" class="iconfont header-back">&#xe624;</div>
      </router-link>
      景点详情
    </div>
	</div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: false,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
      if (top > 60){
        let opacity = top/140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showAbs = true
      } else {
        this.showAbs = false
      }
    },
    //暂时解决方案  keepalive 设置 eclude引起的bug
    handleRemoveScroll () {
      window.removeEventListener('scroll',this.handleScroll)
    }
  },
  //暂时解决方案  keepalive 设置 eclude引起的bug
  mounted () {
    window.addEventListener('scroll',this.handleScroll)
    // window.addEventListener('touchmove',this.handleScroll)
  },
  //使用keepalive后多出的函数 每一次页面展示的时候执行
  // activated () {
  //   window.addEventListener('scroll',this.handleScroll)
  // },
  //页面被隐藏 或者被替换的时候执行
  // deactivated () {
  //   window.removeEventListener('scroll',this.handleScroll)
  // }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
  .header-abs
    position: absolute
    left: .2rem
    top: .2rem
    width: .8rem
    height: .8rem
    line-height: .8rem
    text-align: center
    border-radius: .4rem
    background: rgba(0,0,0,.8)
    .header-abs-back
      font-size: .4rem
      color: #fff
  .header-fixed
    position: fixed
    top: 0
    left: 0
    right: 0
    line-height: $headerHeight
    Height: $headerHeight
    background: $bgColor
    text-align: center
    color: #fff
    z-index: 98
    .header-back
      position: absolute
      top: 0
      left: .1rem
      width: .4rem
      color: #fff
      text-align: center
      font-size: .4rem
</style>
